package com.heima.pri03;

import java.io.*;
import java.util.ArrayList;

public class SpecialDuiXiangLiu04 {
    //用对象操作流读写多个对象
    //练习：创建多个JavaBean类对象写到文件中，再次读取到内存
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Sutdent su = new Sutdent("张三", 22);
        Sutdent su2 = new Sutdent("李四", 33);
        Sutdent su3 = new Sutdent("王五", 55);
        ArrayList<Sutdent> arr = new ArrayList<>();
        arr.add(su);
        arr.add(su2);
        arr.add(su3);
        ObjectOutputStream ob = new ObjectOutputStream(new FileOutputStream("day11\\a.txt"));
        ob.writeObject(arr);
        ob.close();
        ObjectInputStream oi = new ObjectInputStream(new FileInputStream("day11\\a.txt"));
        ArrayList<Sutdent> o = (ArrayList<Sutdent>) oi.readObject();
        for (Sutdent sutdent : o) {
            System.out.println(sutdent);
        }
        oi.close();
    }
}
